var D = YAHOO.util.Dom, E = YAHOO.util.Event;
var STRNULLACTIONRESULT = "爹哋，妈咪，今天 你们行动了么？宝宝好像和爹哋还有妈咪做游戏哟~~不要偷懒，宝宝在等你们的哟 ~~";
var STRACTIONRESULT = "亲爱的爸爸、妈妈，能不能为我写写日记呢？虽然宝宝还不会写字，但宝宝很想把你们为宝宝做的点点滴滴都记下来。等长大了，识字了，宝宝会......";
var treeContentId;
var dailyActionDate;
var treeContentForm;
var treeContentUrl;
var currentActionDate;

var onedivOneTreetext;
var twodivOneTreetext;
var onedivTwoTreetext;
var twodivTwoTreetext;
var onedivThreeTreetext;
var twodivThreeTreetexts;

var fckeditorbabydaily;

function FCKeditor_OnComplete(){
	 onedivOneTreetext = FCKeditorAPI.GetInstance("onedivOneTreetext") ;
	 twodivOneTreetext = FCKeditorAPI.GetInstance("twodivOneTreetext") ;

	 onedivTwoTreetext = FCKeditorAPI.GetInstance("onedivTwoTreetext") ;
	 twodivTwoTreetext = FCKeditorAPI.GetInstance("twodivTwoTreetext") ;

	 onedivThreeTreetext = FCKeditorAPI.GetInstance("onedivThreeTreetext") ;
	 twodivThreeTreetext = FCKeditorAPI.GetInstance("twodivThreeTreetext") ;
	 
	 onedivOneTreetext.Events.AttachEvent( 'OnBlur' , fCKeditor_OnBlur ) ; 
	 onedivOneTreetext.Events.AttachEvent( 'OnFocus' , fCKeditor_OnFocus );
	 
	 twodivOneTreetext.Events.AttachEvent( 'OnBlur' , fCKeditor_OnBlur ) ; 
	 twodivOneTreetext.Events.AttachEvent( 'OnFocus' , fCKeditor_OnFocus );
	 
	 onedivTwoTreetext.Events.AttachEvent( 'OnBlur' , fCKeditor_OnBlur ) ; 
	 onedivTwoTreetext.Events.AttachEvent( 'OnFocus' , fCKeditor_OnFocus );
	 
	 twodivTwoTreetext.Events.AttachEvent( 'OnBlur' , fCKeditor_OnBlur ) ; 
	 twodivTwoTreetext.Events.AttachEvent( 'OnFocus' , fCKeditor_OnFocus );
	 
	 onedivThreeTreetext.Events.AttachEvent( 'OnBlur' , fCKeditor_OnBlur ) ; 
	 onedivThreeTreetext.Events.AttachEvent( 'OnFocus' , fCKeditor_OnFocus );
	 
	 twodivThreeTreetext.Events.AttachEvent( 'OnBlur' , fCKeditor_OnBlur ) ; 
	 twodivThreeTreetext.Events.AttachEvent( 'OnFocus' , fCKeditor_OnFocus );
}

function fCKeditor_OnFocus(o)
{
	if(o.GetXHTML(false).indexOf(STRACTIONRESULT) != -1 || o.GetXHTML(false).indexOf(STRNULLACTIONRESULT) != -1){
		fckeditorbabydaily = o.GetXHTML(true);
	    o.EditorDocument.body.innerHTML="";  
	}else{
		fckeditorbabydaily = "";
	}
} 
function fCKeditor_OnBlur(o){
	if(o.GetXHTML(true) == ""){
		if(fckeditorbabydaily.indexOf(STRACTIONRESULT) != -1 || fckeditorbabydaily.indexOf(STRNULLACTIONRESULT) != -1 ){
			o.SetHTML(fckeditorbabydaily);
		  }  
	}
}

function clearHtmlContent(id,flag){
	
	var fckeditor = FCKeditorAPI.GetInstance(id) ;
	
	if(flag == 'true'){
		fckeditor.SetHTML("");
	}
}

KISSY().use(
		"*",
		function(S) {
			var el = D.get('J_slide'), activeIndex = parseInt(el
					.getAttribute('data-active-index')) || 0;

			var carousel = new S.Carousel(el, {
				hasTriggers : false,
				navCls : 'ks-switchable-nav',
				contentCls : 'ks-switchable-content',
				activeTriggerCls : 'current',
				effect : "scrollx",
				steps : 1,
				viewSize : [ 0 ],
				activeIndex : activeIndex
			});

			E.on('J_week_prev', 'click', carousel.prev, carousel, true);
			E.on('J_day_prev', 'click', carousel.prev, carousel, true);
			E.on('J_week_next', 'click', carousel.next, carousel, true);
			E.on('J_day_next', 'click', carousel.next, carousel, true);
			E.on('J_day_current', 'click', carousel.next, carousel, true);
			E.on('J_input_date', 'click', carousel.next, carousel, true);
		});

function getDateTime(date) {
	var thisYear = date.getFullYear();
	var thisMonth = date.getMonth() + 1;
	if (thisMonth < 10)
		thisMonth = "0" + thisMonth;
	var thisDay = date.getDate();
	if (thisDay < 10)
		thisDay = "0" + thisDay;

	return thisYear + "-" + thisMonth + "-" + thisDay;
}

function toCurrentDay(url) {
	extendOneDivTwo();
	extendTwoDivTwo();
	menuOneDivTwo('action');
	menuTwoDivtwo('action');
	
	$.getJSON(url, {
		curDate : $("#currShowDate").val(),
		type : 'curDay'
	}, function(action) {
		if (action.flag == "TIMEOUT") {
			alert("你登陆时间过长，请重新登录.");
			var loginUrl = url.replace("service/changePage.json","login?type=redirect");
			window.location.href = loginUrl;
		}else if(action.flag == "ERROR"){
			alert("服务器错误,请稍后再试.");
		}else if(action.length == 0){
			alert("已经是今天,或者没有可显示数据.");
		}else {
			showData(action);
			document.getElementById("J_day_current").click();
		}
	});
}

function toInputDay(url) {
	extendOneDivTwo();
	extendTwoDivTwo();
	menuOneDivTwo('action');
	menuTwoDivtwo('action');
    
	$.getJSON(url, {
		curDate : $("#currShowDate").val(),
		type : 'inputDay'
	}, function(action) {
		if (action.flag == "TIMEOUT") {
			alert("你登陆时间过长，请重新登录.");
			var loginUrl = url.replace("service/changePage.json","login?type=redirect");
			window.location.href = loginUrl;
		}else if(action.flag == "ERROR"){
			alert("服务器错误,请稍后再试.");
		}else if(action.length == 0){
			alert("没有可显示数据.");
		}else {
			showData(action);
			document.getElementById("J_input_date").click();
		}
	});
}

function weekPre(url) {
	extendOneDivTwo();
	extendTwoDivTwo();
	menuOneDivTwo('action');
	menuTwoDivtwo('action');

	$.getJSON(url, {
		curDate : $("#currShowDate").val(),
		type : 'preWeek'
	}, function(action) {
		if (action.flag == "TIMEOUT") {
			alert("你登陆时间过长，请重新登录.");
			var loginUrl = url.replace("service/changePage.json","login?type=redirect");
			window.location.href = loginUrl;
		}else if(action.flag == "ERROR"){
			alert("服务器错误,请稍后再试.");
		}else if(action.length == 0){
			alert("没有可显示数据.");
		}else {
			showData(action);
			document.getElementById("J_week_prev").click();
		}
	});
}

function dayPre(url) {
	extendOneDivTwo();
	extendTwoDivTwo();
	menuOneDivTwo('action');
	menuTwoDivtwo('action');

	$.getJSON(url, {
		curDate : $("#currShowDate").val(),
		type : 'preDay'
	}, function(action) {
		if (action.flag == "TIMEOUT") {
			alert("你登陆时间过长，请重新登录.");
			var loginUrl = url.replace("service/changePage.json","login?type=redirect");
			window.location.href = loginUrl;
		}else if(action.flag == "ERROR"){
			alert("服务器错误,请稍后再试.");
		}else if(action.length == 0){
			alert("没有可显示数据.");
		}else {
			showData(action);
			document.getElementById("J_day_prev").click();
		}
	});

}

function dayNext(url) {
	extendOneDivTwo();
	extendTwoDivTwo();
	menuOneDivTwo('action');
	menuTwoDivtwo('action');

	$.getJSON(url, {
		curDate : $("#currShowDate").val(),
		type : 'nextDay'
	}, function(action) {
		if (action.flag == "TIMEOUT") {
			alert("你登陆时间过长，请重新登录.");
			var loginUrl = url.replace("service/changePage.json","login?type=redirect");
			window.location.href = loginUrl;
		}else if(action.flag == "ERROR"){
			alert("服务器错误,请稍后再试.");
		}else if(action.length == 0){
			alert("没有可显示数据.");
		}else {
			showDataDesc(action);
			document.getElementById("J_day_next").click();
		}
	});

}

function weekNext(url) {
	extendOneDivTwo();
	extendTwoDivTwo();
	menuOneDivTwo('action');
	menuTwoDivtwo('action');

	$.getJSON(url, {
		curDate : $("#currShowDate").val(),
		type : 'nextWeek'
	}, function(action) {
		if (action.flag == "TIMEOUT") {
			alert("你登陆时间过长，请重新登录.");
			var loginUrl = url.replace("service/changePage.json","login?type=redirect");
			window.location.href = loginUrl;
		}else if(action.flag == "ERROR"){
			alert("服务器错误,请稍后再试.");
		}else if(action.length == 0){
			alert("没有可显示数据.");
		}else {
			showDataDesc(action);
			document.getElementById("J_week_next").click();
		}
	});
}

function editBabyDaily(showdiv,hidediv){
	$("#" + showdiv).show();
	$("#" + hidediv).hide();
}

function showData(action) {
	$("#currShowDate").val(action[1].actionDate);

	$("#onediv_one_introtext").html(action[0].introText);
	$("#twodiv_one_introtext").html(action[0].introText);
	$("#onediv_one_date").html(action[0].date);
	$("#twodiv_one_date").html(action[0].date);
	$("#onediv_one_week").html(action[0].week);
	$("#twodiv_one_week").html(action[0].week);
	$("#onediv_one_fulltext").html(action[0].fullText);
	$("#twodiv_one_fulltext").html(action[0].fullText);
	$("#onediv_one_dailynote").html(action[0].dailyNote);
	$("#twodiv_one_dailynote").html(action[0].dailyNote);
	$("#onediv_one_action_date").val(action[0].actionDate);
	$("#twodiv_one_action_date").val(action[0].actionDate);
	if(action[0].babyDailyNull == true){
		$("#onediv_one_editor").show();
		$("#onediv_one_babydailytext").hide();
		$("#twodiv_one_editor").show();
		$("#twodiv_one_babydailytext").hide();
		onedivOneTreetext.SetHTML(action[0].babyDaily);
		twodivOneTreetext.SetHTML(action[0].babyDaily);
	}else{
		$("#onediv_one_editor").hide();
		$("#onediv_one_babydailytext").show();
		$("#onediv_one_babydailycontent").html(action[0].babyDaily);
		$("#twodiv_one_editor").hide();
		$("#twodiv_one_babydailytext").show();
		$("#twodiv_one_babydailycontent").html(action[0].babyDaily);
		onedivOneTreetext.SetHTML(action[0].babyDaily);
		twodivOneTreetext.SetHTML(action[0].babyDaily);
	}
	$("#onediv_one_image").hide();
	$("#twodiv_one_image").hide();
	$("#onediv_one_undo").hide();
	$("#twodiv_one_undo").hide();
	if (action[0].actionResult == 1) {
		$("#onediv_one_image").show();
		$("#twodiv_one_image").show();
		$("#onediv_one_actionResult").hide();
		$("#twodiv_one_actionResult").hide();
	} else {
		$("#onediv_one_undo").show();
		$("#twodiv_one_undo").show();
		$("#onediv_one_actionResult").show();
		$("#twodiv_one_actionResult").show();
	}

	$("#onediv_two_introtext").html(action[1].introText);
	$("#twodiv_two_introtext").html(action[1].introText);
	$("#onediv_two_date").html(action[1].date);
	$("#twodiv_two_date").html(action[1].date);
	$("#onediv_two_week").html(action[1].week);
	$("#twodiv_two_week").html(action[1].week);
	$("#onediv_two_fulltext").html(action[1].fullText);
	$("#twodiv_two_fulltext").html(action[1].fullText);
	$("#onediv_two_dailynote").html(action[1].dailyNote);
	$("#twodiv_two_dailynote").html(action[1].dailyNote);
	$("#onediv_two_action_date").val(action[1].actionDate);
	$("#twodiv_two_action_date").val(action[1].actionDate);

	if(action[1].babyDailyNull == true){
		$("#onediv_two_editor").show();
		$("#onediv_two_babydailytext").hide();
		$("#twodiv_two_editor").show();
		$("#twodiv_two_babydailytext").hide();
		onedivTwoTreetext.SetHTML(action[1].babyDaily);
		twodivTwoTreetext.SetHTML(action[1].babyDaily);
	}else{
		$("#onediv_two_editor").hide();
		$("#onediv_two_babydailytext").show();
		$("#onediv_two_babydailycontent").html(action[1].babyDaily);
		$("#twodiv_two_editor").hide();
		$("#twodiv_two_babydailytext").show();
		$("#twodiv_two_babydailycontent").html(action[1].babyDaily);
		onedivTwoTreetext.SetHTML(action[1].babyDaily);
		twodivTwoTreetext.SetHTML(action[1].babyDaily);
	}
	$("#onediv_two_image").hide();
	$("#twodiv_two_image").hide();
	$("#onediv_two_undo").hide();
	$("#twodiv_two_undo").hide();
	if (action[1].actionResult == 1) {
		$("#onediv_two_image").show();
		$("#twodiv_two_image").show();
		$("#onediv_two_actionResult").hide();
		$("#twodiv_two_actionResult").hide();
	} else {
		$("#onediv_two_undo").show();
		$("#twodiv_two_undo").show();
		$("#onediv_two_actionResult").show();
		$("#twodiv_two_actionResult").show();
	}

	$("#onediv_three_introtext").html(action[2].introText);
	$("#twodiv_three_introtext").html(action[2].introText);
	$("#onediv_three_date").html(action[2].date);
	$("#twodiv_three_date").html(action[2].date);
	$("#onediv_three_week").html(action[2].week);
	$("#twodiv_three_week").html(action[2].week);
	$("#onediv_three_fulltext").html(action[2].fullText);
	$("#twodiv_three_fulltext").html(action[2].fullText);
	$("#onediv_three_dailynote").html(action[2].dailyNote);
	$("#twodiv_three_dailynote").html(action[2].dailyNote);
	$("#onediv_three_action_date").val(action[2].actionDate);
	$("#twodiv_three_action_date").val(action[2].actionDate);
	if(action[2].babyDailyNull == null){
		$("#onediv_three_editButton").hide();
		$("#twodiv_three_editButton").hide();
		$("#onediv_three_editor").hide();
		$("#onediv_three_babydailytext").show();
		$("#twodiv_three_editor").hide();
		$("#twodiv_three_babydailytext").show();
		$("#onediv_three_babydailycontent").html(action[2].babyDaily);
		$("#twodiv_three_babydailycontent").html(action[2].babyDaily);
	}else if(action[2].babyDailyNull == true){
		$("#onediv_three_editor").show();
		$("#onediv_three_babydailytext").hide();
		$("#twodiv_three_editor").show();
		$("#twodiv_three_babydailytext").hide();
		onedivThreeTreetext.SetHTML(action[2].babyDaily);
		twodivThreeTreetext.SetHTML(action[2].babyDaily);
	}else{
		$("#onediv_three_editor").hide();
		$("#onediv_three_babydailytext").show();
		$("#onediv_three_babydailycontent").html(action[2].babyDaily);
		$("#twodiv_three_editor").hide();
		$("#twodiv_three_babydailytext").show();
		$("#twodiv_three_babydailycontent").html(action[2].babyDaily);
		onedivThreeTreetext.SetHTML(action[2].babyDaily);
		twodivThreeTreetext.SetHTML(action[2].babyDaily);
		$("#onediv_three_editButton").show();
		$("#twodiv_three_editButton").show();
	}
	$("#onediv_three_image").hide();
	$("#twodiv_three_image").hide();
	$("#onediv_three_undo").hide();
	$("#twodiv_three_undo").hide();
	if (action[2].actionResult == 1) {
		$("#onediv_three_image").show();
		$("#twodiv_three_image").show();
		$("#onediv_three_actionResult").hide();
		$("#twodiv_three_actionResult").hide();
	} else {
		$("#onediv_three_undo").show();
		$("#twodiv_three_undo").show();
		$("#onediv_three_actionResult").show();
		$("#twodiv_three_actionResult").show();
	}
}

function showDataDesc(action) {
	$("#currShowDate").val(action[1].actionDate);

	$("#onediv_one_introtext").html(action[2].introText);
	$("#twodiv_one_introtext").html(action[2].introText);
	$("#onediv_one_date").html(action[2].date);
	$("#twodiv_one_date").html(action[2].date);
	$("#onediv_one_week").html(action[2].week);
	$("#twodiv_one_week").html(action[2].week);
	$("#onediv_one_fulltext").html(action[2].fullText);
	$("#twodiv_one_fulltext").html(action[2].fullText);
	$("#onediv_one_dailynote").html(action[2].dailyNote);
	$("#twodiv_one_dailynote").html(action[2].dailyNote);
	$("#onediv_one_action_date").val(action[2].actionDate);
	$("#twodiv_one_action_date").val(action[2].actionDate);
	if(action[2].babyDailyNull == true){
		$("#onediv_one_editor").show();
		$("#onediv_one_babydailytext").hide();
		$("#twodiv_one_editor").show();
		$("#twodiv_one_babydailytext").hide();
		onedivOneTreetext.SetHTML(action[2].babyDaily);
		twodivOneTreetext.SetHTML(action[2].babyDaily);
	}else{
		$("#onediv_one_editor").hide();
		$("#onediv_one_babydailytext").show();
		$("#onediv_one_babydailycontent").html(action[2].babyDaily);
		$("#twodiv_one_editor").hide();
		$("#twodiv_one_babydailytext").show();
		$("#twodiv_one_babydailycontent").html(action[2].babyDaily);
		onedivOneTreetext.SetHTML(action[2].babyDaily);
		twodivOneTreetext.SetHTML(action[2].babyDaily);
	}
	$("#onediv_one_image").hide();
	$("#twodiv_one_image").hide();
	$("#onediv_one_undo").hide();
	$("#twodiv_one_undo").hide();
	if (action[2].actionResult == 1) {
		$("#onediv_one_image").show();
		$("#twodiv_one_image").show();
		$("#onediv_one_actionResult").hide();
		$("#twodiv_one_actionResult").hide();
	} else {
		$("#onediv_one_undo").show();
		$("#twodiv_one_undo").show();
		$("#onediv_one_actionResult").show();
		$("#twodiv_one_actionResult").show();
	}

	$("#onediv_two_introtext").html(action[1].introText);
	$("#twodiv_two_introtext").html(action[1].introText);
	$("#onediv_two_date").html(action[1].date);
	$("#twodiv_two_date").html(action[1].date);
	$("#onediv_two_week").html(action[1].week);
	$("#twodiv_two_week").html(action[1].week);
	$("#onediv_two_fulltext").html(action[1].fullText);
	$("#twodiv_two_fulltext").html(action[1].fullText);
	$("#onediv_two_dailynote").html(action[1].dailyNote);
	$("#twodiv_two_dailynote").html(action[1].dailyNote);
	$("#onediv_two_action_date").val(action[1].actionDate);
	$("#twodiv_two_action_date").val(action[1].actionDate);
	if(action[1].babyDailyNull == true){
		$("#onediv_two_editor").show();
		$("#onediv_two_babydailytext").hide();
		$("#twodiv_two_editor").show();
		$("#twodiv_two_babydailytext").hide();
		onedivTwoTreetext.SetHTML(action[1].babyDaily);
		twodivTwoTreetext.SetHTML(action[1].babyDaily);
	}else{
		$("#onediv_two_editor").hide();
		$("#onediv_two_babydailytext").show();
		$("#onediv_two_babydailycontent").html(action[1].babyDaily);
		$("#twodiv_two_editor").hide();
		$("#twodiv_two_babydailytext").show();
		$("#twodiv_two_babydailycontent").html(action[1].babyDaily);
		onedivTwoTreetext.SetHTML(action[1].babyDaily);
		twodivTwoTreetext.SetHTML(action[1].babyDaily);
	}
	$("#onediv_two_image").hide();
	$("#twodiv_two_image").hide();
	$("#onediv_two_undo").hide();
	$("#twodiv_two_undo").hide();
	if (action[1].actionResult == 1) {
		$("#onediv_two_image").show();
		$("#twodiv_two_image").show();
		$("#onediv_two_actionResult").hide();
		$("#twodiv_two_actionResult").hide();
	} else {
		$("#onediv_two_undo").show();
		$("#twodiv_two_undo").show();
		$("#onediv_two_actionResult").show();
		$("#twodiv_two_actionResult").show();
	}

	$("#onediv_three_introtext").html(action[0].introText);
	$("#twodiv_three_introtext").html(action[0].introText);
	$("#onediv_three_date").html(action[0].date);
	$("#twodiv_three_date").html(action[0].date);
	$("#onediv_three_week").html(action[0].week);
	$("#twodiv_three_week").html(action[0].week);
	$("#onediv_three_fulltext").html(action[0].fullText);
	$("#twodiv_three_fulltext").html(action[0].fullText);
	$("#onediv_three_dailynote").html(action[0].dailyNote);
	$("#twodiv_three_dailynote").html(action[0].dailyNote);
	$("#onediv_three_action_date").val(action[0].actionDate);
	$("#twodiv_three_action_date").val(action[0].actionDate);

	if(action[0].babyDailyNull == null){
		$("#onediv_three_editButton").hide();
		$("#twodiv_three_editButton").hide();
		$("#onediv_three_editor").hide();
		$("#onediv_three_babydailytext").show();
		$("#twodiv_three_editor").hide();
		$("#twodiv_three_babydailytext").show();
		$("#onediv_three_babydailycontent").html(action[0].babyDaily);
		$("#twodiv_three_babydailycontent").html(action[0].babyDaily);
	}else if(action[0].babyDailyNull == true){
		$("#onediv_three_editor").show();
		$("#onediv_three_babydailytext").hide();
		$("#twodiv_three_editor").show();
		$("#twodiv_three_babydailytext").hide();
		onedivThreeTreetext.SetHTML(action[0].babyDaily);
		twodivThreeTreetext.SetHTML(action[0].babyDaily);
	}else{
		$("#onediv_three_editor").hide();
		$("#onediv_three_babydailytext").show();
		$("#onediv_three_babydailycontent").html(action[0].babyDaily);
		$("#twodiv_three_editor").hide();
		$("#twodiv_three_babydailytext").show();
		$("#twodiv_three_babydailycontent").html(action[0].babyDaily);
		onedivThreeTreetext.SetHTML(action[0].babyDaily);
		twodivThreeTreetext.SetHTML(action[0].babyDaily);
		$("#onediv_three_editButton").show();
		$("#twodiv_three_editButton").show();
	}
	$("#onediv_three_image").hide();
	$("#twodiv_three_image").hide();
	$("#onediv_three_undo").hide();
	$("#twodiv_three_undo").hide();
	if (action[0].actionResult == 1) {
		$("#onediv_three_image").show();
		$("#twodiv_three_image").show();
		$("#onediv_three_actionResult").hide();
		$("#twodiv_three_actionResult").hide();
	} else {
		$("#onediv_three_undo").show();
		$("#twodiv_three_undo").show();
		$("#onediv_three_actionResult").show();
		$("#twodiv_three_actionResult").show();
	}
}

function extendOneDivOne() {
	$("#onediv_one_bottom").hide();
	$("#onediv_one_info").show();

	$("#onediv_two_bottom").show();
	$("#onediv_two_info").hide();

	$("#onediv_three_bottom").show();
	$("#onediv_three_info").hide();
}

function extendOneDivTwo() {
	$("#onediv_one_bottom").show();
	$("#onediv_one_info").hide();

	$("#onediv_two_bottom").hide();
	$("#onediv_two_info").show();

	$("#onediv_three_bottom").show();
	$("#onediv_three_info").hide();
}

function extendOneDivThree() {
	$("#onediv_one_bottom").show();
	$("#onediv_one_info").hide();

	$("#onediv_two_bottom").show();
	$("#onediv_two_info").hide();

	$("#onediv_three_bottom").hide();
	$("#onediv_three_info").show();
}

function extendTwoDivOne() {
	$("#twodiv_one_bottom").hide();
	$("#twodiv_one_info").show();

	$("#twodiv_two_bottom").show();
	$("#twodiv_two_info").hide();

	$("#twodiv_three_bottom").show();
	$("#twodiv_three_info").hide();
}

function extendTwoDivTwo() {
	$("#twodiv_one_bottom").show();
	$("#twodiv_one_info").hide();

	$("#twodiv_two_bottom").hide();
	$("#twodiv_two_info").show();

	$("#twodiv_three_bottom").show();
	$("#twodiv_three_info").hide();
}

function extendTwoDivThree() {
	$("#twodiv_one_bottom").show();
	$("#twodiv_one_info").hide();

	$("#twodiv_two_bottom").show();
	$("#twodiv_two_info").hide();

	$("#twodiv_three_bottom").hide();
	$("#twodiv_three_info").show();
}

function menuOneDivOne(type) {
	if ("action" == type) {
		$("#onedive_one_action").attr("class", "tabsSelected");
		$("#onedive_one_read").attr("class", "tabsUnselected");
		$("#onedive_one_tree").attr("class", "tabsUnselected");

		$("#onedive_one_action_content").show();
		$("#onedive_one_read_content").hide();
		$("#onedive_one_tree_content").hide();
	}
	if ("read" == type) {
		$("#onedive_one_action").attr("class", "tabsUnselected");
		$("#onedive_one_read").attr("class", "tabsSelected");
		$("#onedive_one_tree").attr("class", "tabsUnselected");

		$("#onedive_one_action_content").hide();
		$("#onedive_one_read_content").show();
		$("#onedive_one_tree_content").hide();
	}
	if ("tree" == type) {
		$("#onedive_one_action").attr("class", "tabsUnselected");
		$("#onedive_one_read").attr("class", "tabsUnselected");
		$("#onedive_one_tree").attr("class", "tabsSelected");

		$("#onedive_one_action_content").hide();
		$("#onedive_one_read_content").hide();
		$("#onedive_one_tree_content").show();
	}
}

function menuOneDivTwo(type) {
	if ("action" == type) {
		$("#onedive_two_action").attr("class", "tabsSelected");
		$("#onedive_two_read").attr("class", "tabsUnselected");
		$("#onedive_two_tree").attr("class", "tabsUnselected");

		$("#onedive_two_action_content").show();
		$("#onedive_two_read_content").hide();
		$("#onedive_two_tree_content").hide();
	}
	if ("read" == type) {
		$("#onedive_two_action").attr("class", "tabsUnselected");
		$("#onedive_two_read").attr("class", "tabsSelected");
		$("#onedive_two_tree").attr("class", "tabsUnselected");

		$("#onedive_two_action_content").hide();
		$("#onedive_two_read_content").show();
		$("#onedive_two_tree_content").hide();
	}
	if ("tree" == type) {
		$("#onedive_two_action").attr("class", "tabsUnselected");
		$("#onedive_two_read").attr("class", "tabsUnselected");
		$("#onedive_two_tree").attr("class", "tabsSelected");

		$("#onedive_two_action_content").hide();
		$("#onedive_two_read_content").hide();
		$("#onedive_two_tree_content").show();
	}
}

function menuOneDivThree(type) {
	if ("action" == type) {
		$("#onedive_three_action").attr("class", "tabsSelected");
		$("#onedive_three_read").attr("class", "tabsUnselected");
		$("#onedive_three_tree").attr("class", "tabsUnselected");

		$("#onedive_three_action_content").show();
		$("#onedive_three_read_content").hide();
		$("#onedive_three_tree_content").hide();
	}
	if ("read" == type) {
		$("#onedive_three_action").attr("class", "tabsUnselected");
		$("#onedive_three_read").attr("class", "tabsSelected");
		$("#onedive_three_tree").attr("class", "tabsUnselected");

		$("#onedive_three_action_content").hide();
		$("#onedive_three_read_content").show();
		$("#onedive_three_tree_content").hide();
	}
	if ("tree" == type) {
		$("#onedive_three_action").attr("class", "tabsUnselected");
		$("#onedive_three_read").attr("class", "tabsUnselected");
		$("#onedive_three_tree").attr("class", "tabsSelected");

		$("#onedive_three_action_content").hide();
		$("#onedive_three_read_content").hide();
		$("#onedive_three_tree_content").show();
	}
}

function menuTwoDivOne(type) {
	if ("action" == type) {
		$("#twodive_one_action").attr("class", "tabsSelected");
		$("#twodive_one_read").attr("class", "tabsUnselected");
		$("#twodive_one_tree").attr("class", "tabsUnselected");

		$("#twodive_one_action_content").show();
		$("#twodive_one_read_content").hide();
		$("#twodive_one_tree_content").hide();
	}
	if ("read" == type) {
		$("#twodive_one_action").attr("class", "tabsUnselected");
		$("#twodive_one_read").attr("class", "tabsSelected");
		$("#twodive_one_tree").attr("class", "tabsUnselected");

		$("#twodive_one_action_content").hide();
		$("#twodive_one_read_content").show();
		$("#twodive_one_tree_content").hide();
	}
	if ("tree" == type) {
		$("#twodive_one_action").attr("class", "tabsUnselected");
		$("#twodive_one_read").attr("class", "tabsUnselected");
		$("#twodive_one_tree").attr("class", "tabsSelected");

		$("#twodive_one_action_content").hide();
		$("#twodive_one_read_content").hide();
		$("#twodive_one_tree_content").show();
	}
}

function menuTwoDivtwo(type) {
	if ("action" == type) {
		$("#twodive_two_action").attr("class", "tabsSelected");
		$("#twodive_two_read").attr("class", "tabsUnselected");
		$("#twodive_two_tree").attr("class", "tabsUnselected");

		$("#twodive_two_action_content").show();
		$("#twodive_two_read_content").hide();
		$("#twodive_two_tree_content").hide();
	}
	if ("read" == type) {
		$("#twodive_two_action").attr("class", "tabsUnselected");
		$("#twodive_two_read").attr("class", "tabsSelected");
		$("#twodive_two_tree").attr("class", "tabsUnselected");

		$("#twodive_two_action_content").hide();
		$("#twodive_two_read_content").show();
		$("#twodive_two_tree_content").hide();
	}
	if ("tree" == type) {
		$("#twodive_two_action").attr("class", "tabsUnselected");
		$("#twodive_two_read").attr("class", "tabsUnselected");
		$("#twodive_two_tree").attr("class", "tabsSelected");

		$("#twodive_two_action_content").hide();
		$("#twodive_two_read_content").hide();
		$("#twodive_two_tree_content").show();
	}
}

function menuTwoDivthree(type) {
	if ("action" == type) {
		$("#twodive_three_action").attr("class", "tabsSelected");
		$("#twodive_three_read").attr("class", "tabsUnselected");
		$("#twodive_three_tree").attr("class", "tabsUnselected");

		$("#twodive_three_action_content").show();
		$("#twodive_three_read_content").hide();
		$("#twodive_three_tree_content").hide();
	}
	if ("read" == type) {
		$("#twodive_three_action").attr("class", "tabsUnselected");
		$("#twodive_three_read").attr("class", "tabsSelected");
		$("#twodive_three_tree").attr("class", "tabsUnselected");

		$("#twodive_three_action_content").hide();
		$("#twodive_three_read_content").show();
		$("#twodive_three_tree_content").hide();
	}
	if ("tree" == type) {
		$("#twodive_three_action").attr("class", "tabsUnselected");
		$("#twodive_three_read").attr("class", "tabsUnselected");
		$("#twodive_three_tree").attr("class", "tabsSelected");

		$("#twodive_three_action_content").hide();
		$("#twodive_three_read_content").hide();
		$("#twodive_three_tree_content").show();
	}
}

function validate(id, date, form, url) {
	treeContentId = id;
	dailyActionDate = date;
	treeContentForm = form;
	treeContentUrl = url;

	setTimeout("saveTreeContent()", 50);
	return false;
}

function saveTreeContent() {
	var contentValue = document.getElementById(treeContentId).value;
	var actionDate = document.getElementById(dailyActionDate).value;
	var action_result;
	var doImage = dailyActionDate.replace("action_date", "image");
	var undoImage = dailyActionDate.replace("action_date", "undo");
	var actionResultDiv = dailyActionDate
			.replace("action_date", "actionResult");

	for ( var i = 0; i < treeContentForm.action_result.length; i++) {
		if (treeContentForm.action_result[i].checked) {
			action_result = treeContentForm.action_result[i].value;
		}
	}

	if (contentValue == "") {
		alert("你还没有输入成长日志内容.");
		return;
	}
	contentValue = encodeURI(contentValue);

	$.getJSON(treeContentUrl, {
		contentValue : contentValue,
		actionDate : actionDate,
		actionResult : action_result
	}, function(callback) {
		if (callback.flag == "SUCCESS") {
			if (action_result == "1") {
				document.getElementById(actionResultDiv).style.display = "none"; // 隐藏
				document.getElementById(undoImage).style.display = "none"; // 隐藏
				document.getElementById(doImage).style.display = ""; // 显示
			}
			alert("成长日志保存成功.");
		}else if(callback.flag == "TIMEOUT"){
			alert("你登陆时间过长，请重新登录.");
			var loginUrl = treeContentUrl.replace("service/saveContent.json","login?type=redirect");
			window.location.href = loginUrl;
		}else{
			alert("服务器错误,请稍后再试.");
		}
	});
	
}


// 分享文章
function shareContent(actionDate, url) {
	currentActionDate = document.getElementById(actionDate).value;
	$("#userInputEmail").val("");

	$.getJSON(url, {
		actionDate : currentActionDate
	}, function(action) {
		if (action.flag == "TIMEOUT") {
			alert("你登陆时间过长，请重新登录.");
			var loginUrl = url.replace("service/shareContent.json","login?type=redirect");
			window.location.href = loginUrl;
		} else if(action.flag == "ERROR"){
			alert("服务器错误,请稍后再试.");
		}else {
			showCenterDiv("#popUpWrapInsideId");
			$("#shareActionContentId").val(action.url);
			$("#lockUserActionBodyDivId").show();
			$("#popUpWrapInsideId").show();
		}
	});
}

function selSharebabydaily(url, obj) {
	$.getJSON(url, {
		shareBabyDaily : obj,
		actionDate : currentActionDate
	}, function(callback) {
		if (callback.flag == "SUCCESS") {
			alert("修改成功.");
		}else if(callback.flag == "TIMEOUT"){
			alert("你登陆时间过长，请重新登录.");
			var loginUrl = url.replace("service/shareBabydaily.json","login?type=redirect");
			window.location.href = loginUrl;
		}else{
			alert("服务器错误,请稍后再试.");
		}
	});
}

function copyShareUrl() {
	var t = $("#shareActionContentId").val();
	try {
		window.clipboardData.setData('text', t);
		alert("成功复制到剪贴板，可以粘贴到QQ、MSN等发送给朋友！");
	} catch (e) {
		alert("您的浏览器不支持复制功能!");
	}
}

function showCenterDiv(obj)
{
    var h1 = document.body.clientHeight;
    var h2 = document.documentElement.clientHeight;
    var isXhtml = (h2<=h1&&h2!=0)?true:false;
    var body = isXhtml?document.documentElement:document.body;
   
    var wh={left:0,top:0};
    var vwh={w:0,h:0};
    vwh.w=$.browser.msie?parseInt(body.clientWidth):parseInt(window.innerWidth);
    vwh.h=$.browser.msie?parseInt(body.clientHeight):parseInt(window.innerHeight);
    wh.left=(vwh.w/2)-parseInt($(obj).css("width"))/2;
    wh.top=body.scrollTop+(vwh.h/2)-parseInt($(obj).css("height"))/2;
    $(obj).css("top",wh.top);
    $(obj).css("left",wh.left);
    //return wh;
}

function closeShareWin() {
	$("#lockUserActionBodyDivId").hide();
	$("#popUpWrapInsideId").hide();
}

function sendMail(url){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if($("#userInputEmail").val() == ""){
		alert("请输入朋友邮箱.");
		return;
	}
	
	var email = $("#userInputEmail").val().split(";");
	for(var i = 0 ; i < email.length ; i++){
		if(email[i].trim().length > 0){
		  if (!filter.test(email[i])){
		    alert("您输入了不合法邮箱,请仔细检查.");
			return;
		  }
		}
	}
	
	$.getJSON(url, {
		emails : $("#userInputEmail").val(),
		shareUrl : $("#shareActionContentId").val()
	}, function(callback) {
		if (callback.flag == "SUCCESS") {
			alert("邮件发送成功，请提醒朋友检查邮件！");
		}else if(callback.flag == "TIMEOUT"){
			alert("你登陆时间过长，请重新登录.");
			var loginUrl = url.replace("service/sendMail.json","login?type=redirect");
			window.location.href = loginUrl;
		}else{
			alert("发送邮件出现问题，请稍后再试！");
		}
	});
}
